#include "CMenuItem.h"


CMenuItem::CMenuItem(void)
{
	m_iPosX = m_iPosY = 0;
	m_iWidth = m_iHeight = 0;
}


CMenuItem::~CMenuItem(void)
{
}



void CMenuItem::LoadSprite(LPDIRECT3DDEVICE9 d3ddv, LPCSTR filepath)
{
	D3DXIMAGE_INFO _info;
	D3DXGetImageInfoFromFile(filepath,&_info);

	D3DXCreateTextureFromFileEx(d3ddv,
										filepath,
										_info.Width,
										_info.Height,
										_info.MipLevels,
										D3DUSAGE_DYNAMIC,
										_info.Format,
										D3DPOOL_DEFAULT,
										D3DX_DEFAULT,
										D3DX_DEFAULT,
										D3DCOLOR_XRGB(0,0,0),
										&_info,
										NULL,
										&m_pTexture);

	m_iWidth = _info.Width;
	m_iHeight = _info.Height;
}


void CMenuItem::DrawSprite(LPD3DXSPRITE	m_pSprite)
{
	RECT		scrRect;

	scrRect.left	=	0;
	scrRect.top		=	0;
	scrRect.right	=	m_iWidth;
	scrRect.bottom	=	m_iHeight;

	m_pSprite->Draw( m_pTexture , &scrRect , NULL , &D3DXVECTOR3( m_iPosX , m_iPosY , 0 ) , D3DCOLOR_XRGB(255,255,255) );
}


void CMenuItem::SetPosition(int x, int y)
{
	m_iPosX = x;
	m_iPosY = y;
}


void CMenuItem::SetCenterPosition(int x, int y)
{
	m_iPosX = x - m_iWidth / 2;
	m_iPosY = y - m_iHeight / 2;
}


bool CMenuItem::IsClick(int x, int y)
{
	return ((x >= m_iPosX) && (x <= m_iPosX + m_iWidth) && (y >= m_iPosY) && (y <= m_iPosY + m_iHeight));
}